#include <iostream>
#include <vector>
#include "Thread.hpp"
#include "BlockQueue.hpp"
#include <string>
using std::cout;
using std::endl;
using namespace ThreadModule;
int a = 10;

void Consumer(BlockQueue *&bq)
{
    while (true)
    {
        cout << "Consumer: " << bq << endl;
        sleep(1);
    }
}

void Productor(BlockQueue *&bq)
{
    while (true)
    {
        cout << "Productor: " << bq << endl;
        sleep(1);
    }
}

void StartCom(std::vector<Thread<BlockQueue *>> *&threads, int num, BlockQueue *&bq, func_t<BlockQueue *> func)
{
    for (int i = 0; i < num; i++)
    {
        std::string name = "thread -" + std::to_string(1 + i);
        threads->emplace_back(func, bq, name);
        threads->back().Start();
    }
}

void StartConsumer(std::vector<Thread<BlockQueue *>> *&threads, int num, BlockQueue *&bq)
{
    StartCom(threads, num, bq, Consumer);
}

void StartProductor(std::vector<Thread<BlockQueue *>> *&threads, int num, BlockQueue *&bq)
{
    StartCom(threads, num, bq, Productor);
}

void WaitAllThread(std::vector<Thread<BlockQueue *>> &threads)
{
    for (auto &thread : threads)
    {
        thread.Join();
    }
}

int main()
{
    BlockQueue *bq = new BlockQueue();
    std::vector<Thread<BlockQueue *>> threads;
    std::vector<Thread<BlockQueue *>> *pthreads = &threads;
    StartConsumer(pthreads, 1, bq);
    StartProductor(pthreads, 1, bq);
    WaitAllThread(threads);
    return 0;
}